package View;

import Model.MessageContainer;
import Model.StatusMessage;
import catchup.Main;
import java.util.Observable;
import java.util.Observer;
import javax.swing.BoxLayout;
import javax.swing.JPanel;
import org.gnome.gtk.StatusIcon;
import org.gnome.notify.Notification;
import plugins.PluginManager;

/**
 * This is the panel that contains all status messages
 * @author pieterc
 */
public class MessagePanelContainer extends JPanel implements Observer {


    public MessagePanelContainer() {
        BoxLayout b = new BoxLayout(this, BoxLayout.Y_AXIS);
        this.setLayout(b);
    }

    public void addStatus(StatusMessage sm, int index) {
        MessagePanel s = new MessagePanel(sm);
        this.add(s, index);
        s.revalidate();
    }

    public void update(Observable o, Object arg) {
        MessageContainer st = (MessageContainer) arg;
        int newMessages = 0;
        while (!st.empty()){
            addStatus((StatusMessage) st.pop(), st.getLastIndex());
            newMessages ++;
        }
        PluginManager.getInstance().onNewMessages(newMessages);
    }
}
